﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1.Others
{
    class CP
    {
        public static int CPwrite(int top, int left, int n)
        {
            Console.SetCursorPosition(left, top);        //设置光标位置
            int oldtop = top;
            bool tag = true;
            do
            {
                ConsoleKeyInfo info = Console.ReadKey();
                switch (info.Key)
                {
                    case ConsoleKey.Enter:
                        tag = false;
                        break;
                    case ConsoleKey.UpArrow:
                        if (top > oldtop && top <= oldtop + n - 1)
                        {
                            top -= 1;
                            Console.SetCursorPosition(left, top);
                            //Console.Write(top);
                        }
                        else
                        {
                            Console.SetCursorPosition(left, top);
                        }
                        break;
                    case ConsoleKey.DownArrow:
                        if (top >= oldtop && top < oldtop + n - 1)
                        {
                            top += 1;
                            Console.SetCursorPosition(left, top);
                            //Console.Write(top);
                        }
                        else
                        {
                            Console.SetCursorPosition(left, top);
                        }
                        break;
                    default:
                        Console.SetCursorPosition(left, top);
                        break;
                }
            } while (tag);
            return top + 1 - oldtop;
        }
    }
}
